package top.plgxs.basic.one;

import com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl;

/**
 * <p> 内部类 </p>
 *
 * @author Stranger.
 * @since 2022/9/8 11:02
 */
public class InnerClass {
    public static int age = 18;
    public String name = "xiaoming";
    private String sex = "M";

    public String getSex() {
        return this.sex;
    }

    // 成员内部类
    public class A {
        public static final String nameA = "A";
        public String name = "nameA";
        public int ageA = 28;

        public String getInnerClassName() {
            return "out: " + InnerClass.this.name + " , inner: " + name ;
        }
    }

    // 静态内部类
    public static class B{
        public int ageB = 12;
        public static String nameB = "B";

        public static String getNameB() {
            return nameB;
        }

        public int getAgeB() {
            return this.ageB;
        }
    }

    // 局部内部类
    public String getName() {
        final String name = "getName";
        class C {
            private int ageC = 14;
            public static final String nameC = "C";
            public String name = "C";
            public String getNameC() {
                String name = "getNameC";
                System.out.println("局部内部类中方法的name = " + name);  // 1
                System.out.println("局部内部类中成员变量name = " + this.name);  // 5
                System.out.println("外部类里的成员变量name = " + InnerClass.this.name); // 6
                // 如果出现同名的情况，无法再访问 局部内部类所在方法里的同名局部变量
                return name;
            }
        }
        // 局部内部类只能在方法内部使用
        C c = new C();
        System.out.println(c.getNameC());
        return name;
    }

    public static void main(String[] args) {
        // 成员内部类
        InnerClass.A a = new InnerClass().new A();
        System.out.println(a.getInnerClassName());

        // 静态内部类
        InnerClass.B b = new InnerClass.B();
        System.out.println(b.getAgeB() + " , " + B.getNameB());

        new Thread(){
            @Override
            public void run() {

            }
        };

    }
}
